package cc.langk.web.mapper;

import cc.langk.web.entity.SysStaff;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * 用户信息数据库操作类
 */
@Mapper
public interface SysStaffMapper {
    @Delete({
        "delete from sys_staff",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long rowId);

    @Insert({
        "insert into sys_staff (USER_NAME, USER_ACCOUNT, ",
        "STAFF_ACCOUNT_CODE, USER_PASSWORD, ",
        "USER_STATUS, CREATE_TIME)",
        "values (#{userName,jdbcType=VARCHAR}, #{userAccount,jdbcType=VARCHAR}, ",
        "#{staffAccountCode,jdbcType=VARCHAR}, #{userPassword,jdbcType=VARCHAR}, ",
        "#{userStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="rowId", before=false, resultType=Long.class)
    int insert(SysStaff record);

    @Select({
        "select",
        "ROW_ID, USER_NAME, USER_ACCOUNT, STAFF_ACCOUNT_CODE, USER_PASSWORD, USER_STATUS, ",
        "CREATE_TIME",
        "from sys_staff",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="USER_NAME", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_ACCOUNT", property="userAccount", jdbcType=JdbcType.VARCHAR),
        @Result(column="STAFF_ACCOUNT_CODE", property="staffAccountCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_PASSWORD", property="userPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_STATUS", property="userStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    SysStaff selectByPrimaryKey(Long rowId);

    @Select({
        "select",
        "ROW_ID, USER_NAME, USER_ACCOUNT, STAFF_ACCOUNT_CODE, USER_PASSWORD, USER_STATUS, ",
        "CREATE_TIME",
        "from sys_staff"
    })
    @Results({
        @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="USER_NAME", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_ACCOUNT", property="userAccount", jdbcType=JdbcType.VARCHAR),
        @Result(column="STAFF_ACCOUNT_CODE", property="staffAccountCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_PASSWORD", property="userPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_STATUS", property="userStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<SysStaff> selectAll();

    @Update({
        "update sys_staff",
        "set USER_NAME = #{userName,jdbcType=VARCHAR},",
          "USER_ACCOUNT = #{userAccount,jdbcType=VARCHAR},",
          "STAFF_ACCOUNT_CODE = #{staffAccountCode,jdbcType=VARCHAR},",
          "USER_PASSWORD = #{userPassword,jdbcType=VARCHAR},",
          "USER_STATUS = #{userStatus,jdbcType=INTEGER},",
          "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SysStaff record);

    @Select({
            "select",
            "ROW_ID, USER_NAME, USER_ACCOUNT, STAFF_ACCOUNT_CODE, USER_PASSWORD, USER_STATUS, ",
            "CREATE_TIME",
            "from sys_staff",
            "where USER_ACCOUNT = #{account,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="USER_NAME", property="userName", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_ACCOUNT", property="userAccount", jdbcType=JdbcType.VARCHAR),
            @Result(column="STAFF_ACCOUNT_CODE", property="staffAccountCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_PASSWORD", property="userPassword", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_STATUS", property="userStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    SysStaff selectByUserAccount(String account);


    @Select({
            "select",
            "ROW_ID, USER_NAME, USER_ACCOUNT, STAFF_ACCOUNT_CODE, USER_PASSWORD, USER_STATUS, ",
            "CREATE_TIME",
            "from sys_staff",
            "where USER_ACCOUNT = #{account,jdbcType=VARCHAR} AND USER_PASSWORD = #{passwd,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="USER_NAME", property="userName", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_ACCOUNT", property="userAccount", jdbcType=JdbcType.VARCHAR),
            @Result(column="STAFF_ACCOUNT_CODE", property="staffAccountCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_PASSWORD", property="userPassword", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_STATUS", property="userStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    SysStaff selectByUserAccountAndPasswd(@Param("account") String account,@Param("passwd") String passwd);

    @Delete({
            "delete from sys_staff",
            "where ROW_ID = #{account,jdbcType=VARCHAR}"
    })
    int deleteByUserAccount(String account);
}